const path = require("path");
const fs = require("fs");
var MongoClient = require('mongodb').MongoClient;

module.exports.getPage = (req,res)=>{
    fs.readFile(path.join(__dirname,"../view/login.html"),(err,data)=>{

      //设置响应头
        res.setHeader("Content-Type","text/html;charset=utf-8");
        res.end(data);
    })
}

module.exports.getStudent = (req,res)=>{
//console.log(req.body);
      var url = 'mongodb://localhost:27017/hmqd05';
    // Use connect method to connect to the Server 
    MongoClient.connect(url, function(err, db) {
      var collection = db.collection('count');
  // Find some documents 
       collection.findOne({username:req.body.uname,password:req.body.pwd,status:0},(err,doc)=>{
            if (doc!=null) {
               res.end("<script>window.location.href='list';</script>");
            }else{
              res.end("<script>alert('用户或是密码有误');window.location.href='/account/login';</script>");
            }
        });
    });
      
}
